<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="操作标识" prop="operId">
        <el-input
          v-model="queryParams.operId"
          placeholder="请输入操作标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="变更记录标识,储位变更记录" prop="chgId">
        <el-input
          v-model="queryParams.chgId"
          placeholder="请输入变更记录标识,储位变更记录"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库房标识,库房标识" prop="whId">
        <el-input
          v-model="queryParams.whId"
          placeholder="请输入库房标识,库房标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库区标识" prop="whAreaId">
        <el-input
          v-model="queryParams.whAreaId"
          placeholder="请输入库区标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存放区标识" prop="storeAreaId">
        <el-input
          v-model="queryParams.storeAreaId"
          placeholder="请输入存放区标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
        <el-input
          v-model="queryParams.cabinetBarCode"
          placeholder="请输入周转柜资产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原柜单元标识" prop="srcUnitId">
        <el-input
          v-model="queryParams.srcUnitId"
          placeholder="请输入原柜单元标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原储位标识" prop="srcStoreLocId">
        <el-input
          v-model="queryParams.srcStoreLocId"
          placeholder="请输入原储位标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新柜单元标识" prop="unitId">
        <el-input
          v-model="queryParams.unitId"
          placeholder="请输入新柜单元标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新储位标识" prop="storeLocId">
        <el-input
          v-model="queryParams.storeLocId"
          placeholder="请输入新储位标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="变更时间" prop="chgDate">
        <el-date-picker clearable
          v-model="queryParams.chgDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择变更时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="条形码,根据储位存储设备类别不同，有可能是设备条码、周转箱条码、托盘条码" prop="barCode">
        <el-input
          v-model="queryParams.barCode"
          placeholder="请输入条形码,根据储位存储设备类别不同，有可能是设备条码、周转箱条码、托盘条码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类别
01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" prop="equipCateg">
        <el-input
          v-model="queryParams.equipCateg"
          placeholder="请输入设备类别
01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['storage:mdStoreLocChg:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['storage:mdStoreLocChg:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['storage:mdStoreLocChg:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['storage:mdStoreLocChg:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="mdStoreLocChgList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="操作标识" align="center" prop="operId" />
      <el-table-column label="变更记录标识,储位变更记录" align="center" prop="chgId" />
      <el-table-column label="库房标识,库房标识" align="center" prop="whId" />
      <el-table-column label="库区标识" align="center" prop="whAreaId" />
      <el-table-column label="存放区标识" align="center" prop="storeAreaId" />
      <el-table-column label="周转柜资产编号" align="center" prop="cabinetBarCode" />
      <el-table-column label="原柜单元标识" align="center" prop="srcUnitId" />
      <el-table-column label="原储位标识" align="center" prop="srcStoreLocId" />
      <el-table-column label="新柜单元标识" align="center" prop="unitId" />
      <el-table-column label="新储位标识" align="center" prop="storeLocId" />
      <el-table-column label="变更时间" align="center" prop="chgDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chgDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="条形码,根据储位存储设备类别不同，有可能是设备条码、周转箱条码、托盘条码" align="center" prop="barCode" />
      <el-table-column label="设备类别
01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" align="center" prop="equipCateg" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['storage:mdStoreLocChg:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['storage:mdStoreLocChg:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改储位变更记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="操作标识" prop="operId">
          <el-input v-model="form.operId" placeholder="请输入操作标识" />
        </el-form-item>
        <el-form-item label="变更记录标识,储位变更记录" prop="chgId">
          <el-input v-model="form.chgId" placeholder="请输入变更记录标识,储位变更记录" />
        </el-form-item>
        <el-form-item label="库房标识,库房标识" prop="whId">
          <el-input v-model="form.whId" placeholder="请输入库房标识,库房标识" />
        </el-form-item>
        <el-form-item label="库区标识" prop="whAreaId">
          <el-input v-model="form.whAreaId" placeholder="请输入库区标识" />
        </el-form-item>
        <el-form-item label="存放区标识" prop="storeAreaId">
          <el-input v-model="form.storeAreaId" placeholder="请输入存放区标识" />
        </el-form-item>
        <el-form-item label="周转柜资产编号" prop="cabinetBarCode">
          <el-input v-model="form.cabinetBarCode" placeholder="请输入周转柜资产编号" />
        </el-form-item>
        <el-form-item label="原柜单元标识" prop="srcUnitId">
          <el-input v-model="form.srcUnitId" placeholder="请输入原柜单元标识" />
        </el-form-item>
        <el-form-item label="原储位标识" prop="srcStoreLocId">
          <el-input v-model="form.srcStoreLocId" placeholder="请输入原储位标识" />
        </el-form-item>
        <el-form-item label="新柜单元标识" prop="unitId">
          <el-input v-model="form.unitId" placeholder="请输入新柜单元标识" />
        </el-form-item>
        <el-form-item label="新储位标识" prop="storeLocId">
          <el-input v-model="form.storeLocId" placeholder="请输入新储位标识" />
        </el-form-item>
        <el-form-item label="变更时间" prop="chgDate">
          <el-date-picker clearable
            v-model="form.chgDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择变更时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="条形码,根据储位存储设备类别不同，有可能是设备条码、周转箱条码、托盘条码" prop="barCode">
          <el-input v-model="form.barCode" placeholder="请输入条形码,根据储位存储设备类别不同，有可能是设备条码、周转箱条码、托盘条码" />
        </el-form-item>
        <el-form-item label="设备类别
01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" prop="equipCateg">
          <el-input v-model="form.equipCateg" placeholder="请输入设备类别
01：电能表
02：电压互感器
03：电流互感器
04：组合互感器
09：采集终端
21：负控设备
25：采集器" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMdStoreLocChg, getMdStoreLocChg, delMdStoreLocChg, addMdStoreLocChg, updateMdStoreLocChg } from "@/api/storage/mdStoreLocChg";

export default {
  name: "MdStoreLocChg",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 储位变更记录表格数据
      mdStoreLocChgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        operId: null,
        chgId: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        cabinetBarCode: null,
        srcUnitId: null,
        srcStoreLocId: null,
        unitId: null,
        storeLocId: null,
        chgDate: null,
        barCode: null,
        equipCateg: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        operId: [
          { required: true, message: "操作标识不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询储位变更记录列表 */
    getList() {
      this.loading = true;
      listMdStoreLocChg(this.queryParams).then(response => {
        this.mdStoreLocChgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        operId: null,
        chgId: null,
        whId: null,
        whAreaId: null,
        storeAreaId: null,
        cabinetBarCode: null,
        srcUnitId: null,
        srcStoreLocId: null,
        unitId: null,
        storeLocId: null,
        chgDate: null,
        barCode: null,
        equipCateg: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.operId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加储位变更记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const operId = row.operId || this.ids
      getMdStoreLocChg(operId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改储位变更记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.operId != null) {
            updateMdStoreLocChg(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMdStoreLocChg(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const operIds = row.operId || this.ids;
      this.$modal.confirm('是否确认删除储位变更记录编号为"' + operIds + '"的数据项？').then(function() {
        return delMdStoreLocChg(operIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('storage/mdStoreLocChg/export', {
        ...this.queryParams
      }, `mdStoreLocChg_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
